<template>
  <div>
    <div>
      搜索
    </div>
    <el-table :data="tableData" @selection-change="selection">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="id" prop="id"></el-table-column>
      <el-table-column label="题型" prop="questionType" :formatter="formatType"></el-table-column>
      <el-table-column label="题干" prop="shortTitle"></el-table-column>
    </el-table>
  </div>
</template>

<script setup lang="ts">
import QuestionApi, { type queryParams, type questionType} from "@/api/exam/query.api"
import { ref } from "vue"
const tableData = ref<questionType[]>([])
const props=defineProps<{subjectId:number |null}>()
let params = ref<queryParams>({
  id: null,
  questionType: null,
  level: null,
  subjectId: props.subjectId,
  pageIndex: 1,
  pageSize: 10
})
// 获取列表
 function getLIst() {
   QuestionApi.getQuestionPage(params.value).then(data => {
    tableData.value = data.list
  })
 
}
const formatType = (row: any) => {
  switch (row.questionType) {
    case 1:
      return '单选题';
    case 2:
      return '多选题';
    case 3:
      return '判断题';
    case 4:
      return '填空题';
    case 5:
      return '解答题';
    default:
      return "其它";
  }
}
onMounted( () => {
   getLIst()
})
let  ids:number[]=[]
// 子传父
const emit=defineEmits(["sendIds"])
function selection(val:questionType[]){
  // 返回一个新数组
ids=val.map(item=>item.id)

// 子传父
emit("sendIds",ids)
}

</script>

<style scoped>

</style>